#!/usr/bin/python

import sys
from itertools import groupby

if __name__ == "__main__":
    for gene_id, grp in groupby((line.split() for line in sys.stdin), key=lambda i:i[0]):
        print "%s\t%s" % (gene_id, ','.join(map(str, sorted(set(int(g[1]) for g in grp)))))


